package com.glzn.springboot03.mapper;

import com.glzn.springboot03.entity.WaveHead;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Administrator
 */
@Mapper
@Repository
public interface WaveMapper {
	/**
	 * 查找录波总览
	 * @param deviceId
	 * @return
	 */
	@Select("SELECT * FROM wave WHERE device_id=#{deviceId}")
	List<WaveHead> findAll(Integer deviceId);

	/**
	 * 根据ID查询
	 * @param id
	 * @param deviceId
	 * @return
	 */
	@Select("SELECT * FROM wave WHERE id=#{id} AND device_id=#{deviceId}")
	WaveHead findById(int id, Integer deviceId);
	/**
	 * 插入录波总览
	 * @param waveHead
	 * @return
	 */
	@SelectKey(statement = "SELECT MAX(id)+1 FROM wave", keyProperty = "id", before = true, resultType = int.class)
	@Insert("INSERT INTO wave(id,type,happen_time,millsecond,device_id) VALUES(#{id},#{type},#{happenTime},#{millsecond},#{deviceId})")
	boolean insert(WaveHead waveHead);

	/**
	 * 删除所有录波头信息
	 * @param deviceId
	 * @return
	 */
	@Delete("DELETE FROM wave WHERE device_id=#{deviceId}")
	boolean deleteAll(Integer deviceId);
}
